/* eslint valid-jsdoc: "off" */
const path = require('path');
'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_furrytail';

  //跨域配置
  config.cors = {
    origin: '*',
    credentials: true,
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS'
  }

  config.static = {
    dir: 'D:\kenan_img'  //windows本地地址
    // dir: '/Users/qiujingxiu/Desktop/images'  //mac本地地址
    // dir: '/www/wwwroot/images'  //线上地址
  }

  //自动化文档库
  config.swaggerdoc = {
    dirScanner: './app/controller',
    apiInfo: {
      title: '统计接口',
      description: '统计接口文档',
      version: '1.0.0',
    },
    schemes: ['http', 'https'],
    consumes: ['application/json'],
    produces: ['application/json'],
    // enableVilidate: true,  //参数校验，但是不好用
    routerMap: true,  //根据router内容自动完成路由注册
    securityDefinitions: {
      apikey: {
        type: 'apiKey',
        name: 'Authorization',//jwt一般是这名字，根据需要调整
        in: 'header',
      },
    },
    enableSecurity: true,
    enable: true,
  };

  config.appBaseDir= path.join(appInfo.baseDir, 'app'); 

  //写入数据库配置
  // const dbConfig = {
  //   dialect: 'mysql',
  //   database: 'total',
  //   host: '120.26.22.70',
  //   port: '3306',
  //   username: 'total',
  //   password: 'Www558899',
  //   pool: {
  //       max: 20,
  //       idle: 300000,
  //       acquire: 600000
  //   },
  //   timezone: '+08:00', 
  //   define: {
  //     freezeTableName: true,
  //   },
  // };

  // 本地测试库
  const dbConfig = {
    dialect: 'mysql',
    database: 'total_test',
    host: '120.26.22.70',
    port: '3306',
    username: 'total_test',
    password: 'Www558899',
    pool: {
        max: 20,
        idle: 300000,
        acquire: 600000
    },
    timezone: '+08:00', 
    define: {
      freezeTableName: true,
    },
  };


  config.oss={
    client: {
        region: 'oss-cn-hangzhou',
        accessKeyId: 'LTAIwLFtIVOO4IgO',
        accessKeySecret: 'xqiSIzsxAZhZKis18kKt67nXO5Dswg',
        bucket: 'furrytail-wx',
        timeout: 600000
    },
    origin:"https://oss-cn-hangzhou-internal.aliyuncs.com"
  };

  config.sequelize = dbConfig;

  // add your middleware config here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
    multipart: {
      fileExtensions: ['.pdf'], // 增加对 apk 扩展名的文件支持
    },
  };

  return {
    ...config,
    ...userConfig,
  };
};
